package com.zmn.plat.dubbo.impl.orderconfig.track;

import java.util.List;

import javax.annotation.Resource;

import org.apache.dubbo.config.annotation.Service;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.plat.business.interfaces.orderconfig.track.OrderTrackBService;
import com.zmn.plat.common.dto.orderconfig.track.OrderTrackDIO;
import com.zmn.plat.common.dto.orderconfig.track.OrderTrackDRO;
import com.zmn.plat.common.exception.PlatException;
import com.zmn.plat.dubbo.interfaces.orderconfig.track.OrderTrackListRemoteService;
import com.zmn.plat.dubbo.utils.DubboConsts;

import lombok.extern.slf4j.Slf4j;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2020/11/25 18:49
 **/
@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
@Slf4j
public class OrderTrackListRemoteServiceImpl implements OrderTrackListRemoteService {
    @Resource
    private OrderTrackBService orderTrackBService;

    @Override
    @ReadOnlyConnection
    public ResponseDTO<OrderTrackDRO> getById(Integer trackId) {
        log.info("getById trackId:{}", trackId);

        try {
            OrderTrackDRO dro = orderTrackBService.getByTrackId(trackId);
            return ResponseDTO.success(dro);
        } catch (PlatException e) {
            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
        } catch (Exception e) {
            log.error("getById error.trackId={}", trackId, e);
            return ResponseDTO.fail(GlobalConsts.FAILD_MSG);
        }
    }

    @Override
    @ReadOnlyConnection
    public ResponseDTO<List<OrderTrackDRO>> listByTrackIds(List<Integer> trackIds) {
        log.info("listByTrackIds trackIds:{}", trackIds);
        try {
            List<OrderTrackDRO> droList = orderTrackBService.listByTrackIds(trackIds);
            return ResponseDTO.success(droList);
        } catch (PlatException e) {
            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
        } catch (Exception e) {
            log.error("listByTrackIds error.trackIds={}", trackIds, e);
            return ResponseDTO.fail(GlobalConsts.FAILD_MSG);
        }
    }

    @Override
    @ReadOnlyConnection
    public ResponseDTO<List<OrderTrackDRO>> listByCategIdAndBizType(Integer categId, Integer bizType) {
        log.info("listByCategIdAndBizType categId:{},bizType:{}", categId, bizType);
        try {
            List<OrderTrackDRO> droList = orderTrackBService.listByCategIdAndBizType(categId, bizType);
            return ResponseDTO.success(droList);
        } catch (PlatException e) {
            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
        } catch (Exception e) {
            log.error("listByCategIdAndBizType categId:{},bizType:{}", categId, bizType, e);
            return ResponseDTO.fail(GlobalConsts.FAILD_MSG);
        }
    }

    @Override
    @ReadOnlyConnection
    public ResponseDTO<List<OrderTrackDRO>> listByDIO(OrderTrackDIO dio) {
        log.info("listByDIO dio:{}", dio);
        try {
            List<OrderTrackDRO> droList = orderTrackBService.listByDIO(dio);
            return ResponseDTO.success(droList);
        } catch (PlatException e) {
            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
        } catch (Exception e) {
            log.error("listByDIO error.dio={}", dio, e);
            return ResponseDTO.fail(GlobalConsts.FAILD_MSG);
        }
    }
}
